package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 游记推荐
 */
@Getter@Setter
public class TravelCommend extends BaseDomain {
    public static final int TYPE_WEEK=1;//每周推荐
    public static final int TYPE_MONTH=2;//每月推荐
    public static final int TYPE_STRATEGY=3;//攻略推荐

    //关联的游记
    private Travel travel;
    //标题
    private String title;
    //子标题
    private String subTitle;
    //封面
    private String coverUrl;
    //推荐时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date schedule;
    //推荐类型
    private Integer type;





    //页面推荐类型汉字回显
    public String getTypeName() {
        String msg="每周推荐";
        if (type==TravelCommend.TYPE_MONTH) {
            msg="每月推荐";
        }else if (type==TravelCommend.TYPE_STRATEGY){
            msg="攻略推荐";
        }
        return msg;
    }

    /**
     * 增加一个属性 json对象
     * @return
     */
    public String getJson() {
        Map<String,Object> map= new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        map.put("schedule", DateUtil.formatDate(schedule));
        map.put("type",type);
        if(travel!=null){
            map.put("travelId",travel.id);
        }
        return JSONUtil.toJSONString(map);
    }

}